package com.hly.tool.relationship;

import com.matrixone.apps.domain.util.FrameworkException;
import com.matrixone.apps.domain.util.MqlUtil;
import com.matrixone.apps.framework.ui.UIUtil;
import matrix.db.Context;
import matrix.util.StringList;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/10/19 13:48
 * @description：
 */
public class RelationshipUtil
{

    /**
     * 获取一种关联关系上的所有属性的名称
     *
     * @param context
     * @param relName
     */
    public static List<String> getRelationshipAttrNames(Context context, String relName)
    {
        List<String> result = new ArrayList<String>();
        try
        {
            String mql = "print relationship \"" + relName + "\" select attribute dump |";
            String mqlResult = MqlUtil.mqlCommand(context, mql);
            if (UIUtil.isNotNullAndNotEmpty(mqlResult))
            {
                String[] split = mqlResult.split("\\|");
                if (split != null && split.length > 0)
                {
                    result = Arrays.asList(split);
                }

            }
        } catch (FrameworkException e)
        {
            e.printStackTrace();
        }
        return result;
    }
}
